<template>
  <div>
    <el-dialog :title="title" :visible.sync="dialogFormVisible" width="600px">
      <el-menu
        :default-active="type"
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
      >
        <el-menu-item :index="v.index" v-for="(v, i) in MenuList" :key="i">{{
          v.text
        }}</el-menu-item>
      </el-menu>
      <el-divider></el-divider>
      <el-form :model="form">
        <el-form-item
          :label="v.title"
          :label-width="formLabelWidth"
          v-for="(v, i) in ruleList"
          :key="i"
        >
          <el-select
            v-model="form['config_tab_id']"
            clearable
            placeholder="请选择分类"
            v-if="v.field == 'config_tab_id'"
          >
            <el-option
              v-for="(m, n) in v.options"
              :key="n"
              :label="m.label"
              :value="m.value"
            >
            </el-option>
          </el-select>
          <el-select
            v-model="form['input_type']"
            clearable
            placeholder="请选择分类"
            v-if="v.field == 'input_type'"
          >
            <el-option
              v-for="(m, n) in v.options"
              :key="n"
              :label="m.label"
              :value="m.value"
            >
            </el-option>
          </el-select>
          <el-input
            v-model="form['info']"
            :placeholder="v.props.placeholder"
            v-if="v.field == 'info'"
          ></el-input>
          <el-input
            v-model="form['menu_name']"
            :placeholder="v.props.placeholder"
            :disabled="form.id"
            v-if="v.field == 'menu_name'"
          ></el-input>
          <el-input
            v-model="form['desc']"
            :placeholder="v.props.placeholder"
            v-if="v.field == 'desc'"
          ></el-input>
          <el-input
            v-model="form['value']"
            :placeholder="v.props.placeholder"
            v-if="v.field == 'value'"
          ></el-input>

          <el-input-number
            v-model="form['width']"
            :placeholder="v.props.placeholder"
            :min="1"
            :max="100"
            v-if="v.field == 'width'"
            controls-position="right"
          ></el-input-number>

          <el-input
            v-model="form['required']"
            :placeholder="v.props.placeholder"
            v-if="v.field == 'required'"
          ></el-input>

          <el-input-number
            v-model="form['sort']"
            :placeholder="v.props.placeholder"
            :min="1"
            v-if="v.field == 'sort'"
            controls-position="right"
          ></el-input-number>

          <el-radio-group v-model="form.status" v-if="v.field == 'status'">
            <el-radio :label="1">显示</el-radio>
            <el-radio :label="2">隐藏</el-radio>
          </el-radio-group>

          <el-radio-group
            v-model="form['upload_type']"
            v-if="v.field == 'upload_type'"
          >
            <el-radio :label="1">单图</el-radio>
            <el-radio :label="2">多图</el-radio>
            <el-radio :label="3">文件</el-radio>
          </el-radio-group>

          <el-input
            v-model="form['parameter']"
            :placeholder="v.props.placeholder"
            v-if="v.field == 'parameter'"
          ></el-input>

          <el-input-number
            v-model="form['high']"
            :placeholder="v.props.placeholder"
            :min="1"
            :max="100"
            v-if="v.field == 'high'"
            controls-position="right"
          ></el-input-number>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: ["dialogFormVisible", "form", "title", "type", "ruleList"],
  data() {
    return {
      formLabelWidth: "120px",
      MenuList: [
        {
          text: "文本框",
          index: 0,
        },
        {
          text: "多行文本框",
          index: 1,
        },
        {
          text: "单选框",
          index: 2,
        },
        {
          text: "文件上传",
          index: 3,
        },
        {
          text: "多选框",
          index: 4,
        },
        {
          text: "下拉框",
          index: 5,
        },
      ],
    };
  },

  methods: {
    handleSelect(key, keyPath) {
      this.$emit("changeSelect", key);
    },
    submit() {
      this.$emit("finish", this.form);
    },
  },
};
</script>
<style lang="less" scoped></style>
